using Avalonia.Controls;
using Dock.Settings;

namespace QComandAvalonia.Views
{
    public partial class MainView : UserControl
    {
        public MainView()
        {
            InitializeComponent();
            InitializeThemes();
            InitializeMenu();
        }
        private void InitializeThemes()
        {
            var dark = false;
            var theme = this.Find<Button>("ThemeButton");
            if (theme is { })
            {
                theme.Click += (_, _) =>
                {
                    dark = !dark;
                    App.ThemeManager?.Switch(dark ? 1 : 0);
                };
            }
        }
        private void InitializeMenu()
        {
            var optionsIsDragEnabled = this.FindControl<MenuItem>("OptionsIsDragEnabled");
            if (optionsIsDragEnabled is { })
            {
                optionsIsDragEnabled.Click += (_, _) =>
                {
                    if (VisualRoot is Window window)
                    {
                        var isEnabled = window.GetValue(DockProperties.IsDragEnabledProperty);
                        window.SetValue(DockProperties.IsDragEnabledProperty, !isEnabled);
                    }
                };
            }

            var optionsIsDropEnabled = this.FindControl<MenuItem>("OptionsIsDropEnabled");
            if (optionsIsDropEnabled is { })
            {
                optionsIsDropEnabled.Click += (_, _) =>
                {
                    if (VisualRoot is Window window)
                    {
                        var isEnabled = window.GetValue(DockProperties.IsDropEnabledProperty);
                        window.SetValue(DockProperties.IsDropEnabledProperty, !isEnabled);
                    }
                };
            }
        }


    }
}